<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-select v-model="listQuery.typeId" clearable filterable style="width: 200px" class="filter-item" placeholder="应用分类">
        <el-option v-for="item in typeOptions" :key="item.id" :label="item.name" :value="item.id"/>
      </el-select>
      <el-select v-model="listQuery.systemType" clearable filterable style="width: 200px" class="filter-item" placeholder="应用类型">
        <el-option v-for="item in sysTypeOp" :key="item" :label="item" :value="item"/>
      </el-select>
      <el-select v-model="listQuery.level" clearable filterable style="width: 200px" class="filter-item" placeholder="应用级别">
        <el-option v-for="item in levelOptions" :key="item" :label="item" :value="item"/>
      </el-select>
      <el-input v-model="listQuery.name" clearable style="width: 200px;margin-right: 10px;" class="filter-item" placeholder="应用名称"/>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">{{ $t('table.search') }}</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">{{ $t('table.add') }}</el-button>
    </div>

    <el-table v-loading="listLoading" :key="tableKey" :data="list" element-loading-text="加载中" border fit highlight-current-row style="width: 100%">
      <el-table-column :label="$t('table.id')" align="center" width="65">
        <template slot-scope="scope">
          <span>{{ scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.name')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.typeName')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.typeName }}</span>
        </template>
      </el-table-column>
      <el-table-column width="100px" align="center" label="应用类型">
        <template slot-scope="scope">
          <span>{{ scope.row.systemType }}</span>
        </template>
      </el-table-column>
      <el-table-column width="100px" align="center" label="应用特性">
        <template slot-scope="scope">
          <span>{{ featureOptions[scope.row.features].label }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.level')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.level }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.gitUrl')" width="200px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.gitUrl }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.owner')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.ownerName }}</span>
        </template>
      </el-table-column>
      <el-table-column width="200px" align="center" label="主机">
        <template slot-scope="scope">
          <div v-if="scope.row.hostNames.length > 0">
            <p v-for="item in scope.row.hostNames" :key="item.key"><el-tag style="width:100%">{{ item.name }}</el-tag></p>
          </div>
        </template>
      </el-table-column>
      <el-table-column width="200px" align="center" label="k8s环境">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.k8sEnvs" style="width:100%">{{ scope.row.k8sEnvs }} </el-tag>
        </template>
      </el-table-column>
      <el-table-column width="100px" align="center" label="质量">
        <template slot-scope="scope">
          <span>{{ scope.row.qualityName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.develop')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.developNames }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.ports')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.ports }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.redis')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.redis }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.comment')" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.comment }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.createTime')" width="180px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.creator')" width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.creator }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.updateTime')" width="180px">
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.updator')" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.updator }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.actions')" align="center" fixed="right" width="260px" >
        <template slot-scope="scope">
          <el-button type="success" size="small" @click="handleCopyAndAdd(scope.row)">拷贝并添加</el-button>
          <el-button type="primary" size="small" @click="handleUpdate(scope.row)">{{ $t('table.edit') }}</el-button>
          <el-button type="danger" size="small" @click="handleDelete(scope.row)">{{ $t('table.delete') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" :total="total" background layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
    </div>

    <el-dialog :close-on-click-modal="false" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="90px">
        <el-row>
          <el-col :span="22">
            <el-form-item :label="$t('table.name')" prop="name">
              <el-input v-model="temp.name"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('table.typeName')" prop="typeId">
              <el-select v-model="temp.typeId" clearable filterable class="filter-item" style="width:240px" placeholder="请选择应用分类">
                <el-option v-for="item in typeOptions" :key="item.id" :label="item.name" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="应用类型" prop="systemType">
              <el-select v-model="temp.systemType" clearable filterable class="filter-item" style="width:240px" placeholder="请选择应用类型">
                <el-option v-for="item in sysTypeOp" :key="item" :label="item" :value="item"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="应用特性" prop="features">
              <el-select v-model="temp.features" clearable filterable class="filter-item" style="width:240px" placeholder="请选择应用特性">
                <el-option v-for="item in featureOptions" :key="item.key" :label="item.label" :value="item.key"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('table.level')" prop="level">
              <el-select v-model="temp.level" clearable filterable class="filter-item" style="width:240px" placeholder="请选择应用级别">
                <el-option v-for="item in levelOptions" :key="item" :label="item" :value="item"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22" >
            <el-form-item :label="$t('table.gitUrl')" prop="gitUrl">
              <el-input v-model="temp.gitUrl"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('table.comment')" prop="comment">
              <el-input v-model="temp.comment" style="width:240px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('table.owner')" prop="ownerId">
              <el-select v-model="temp.ownerId" clearable filterable style="width:240px" placeholder="请选择负责人">
                <el-option
                  v-for="item in devOptions"
                  :key="item.id"
                  :label="item.nickname"
                  :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="质量负责人">
              <el-select v-model="temp.qualityId" clearable filterable style="width:240px" placeholder="请选择质量负责人">
                <el-option
                  v-for="item in devOptions"
                  :key="item.id"
                  :label="item.nickname"
                  :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('table.develop')" prop="developIds">
              <el-select v-model="developArray" clearable filterable multiple style="width:240px" placeholder="请选择开发者">
                <el-option
                  v-for="item in devOptions"
                  :key="item.id"
                  :label="item.nickname"
                  :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="主机">
              <el-select v-model="hostArray" filterable multiple style="width:240px" placeholder="请选择主机">
                <el-option
                  v-for="item in hostOptions"
                  :key="item.id"
                  :label="item.hostName"
                  :value="item.id">
                  <span style="float: left">{{ item.hostName }}</span>
                  <span style="float: left;margin-left:6px; color: #8492a6; font-size: 13px">{{ item.env }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="K8s环境">
              <el-select v-model="k8sEnvArray" filterable multiple style="width:240px" placeholder="请选择K8s环境">
                <el-option
                  v-for="item in kubernetesEnvOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.name">
                  <span style="float: left">{{ item.name }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('table.ports')" prop="ports">
              <el-select v-model="portsArray" clearable filterable multiple style="width:240px" placeholder="请选择数据库端口">
                <el-option
                  v-for="item in portOptions"
                  :key="item.port"
                  :label="item.port"
                  :value="item.port"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('table.redis')">
              <el-select v-model="redisArray" clearable filterable multiple style="width:240px" placeholder="请选择REDIS实例">
                <el-option
                  v-for="item in redisOptions"
                  :key="item.redis"
                  :label="item.redis"
                  :value="item.redis"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">{{ $t('table.cancel') }}</el-button>
        <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">{{ $t('table.confirm') }}</el-button>
        <el-button v-else type="primary" @click="updateData">{{ $t('table.confirm') }}</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogPvVisible" title="Reading statistics">
      <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
        <el-table-column prop="key" label="Channel"/>
        <el-table-column prop="pv" label="Pv"/>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogPvVisible = false">{{ $t('table.confirm') }}</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import {
  fetchList,
  fetchTypeList,
  fetchPortList,
  fetchRedisList,
  fetchSystemType,
  fetchDevList,
  fetchHostList,
  create,
  update,
  del
} from '@/api/appSystem'
import {
  fetchEnv
} from '@/api/host'

import { parseTime } from '@/utils/index'
export default {
  name: 'ComplexTable',
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      // 格式化主机
      formatHost: function(content) {
        if (!content) {
          return ''
        }

        const strList = []
        if (content.indexOf(',') !== -1) {
          const contentList = content.split(',')
          for (let a = 0; a < contentList.length; a++) {
            const temp = {
              key: a,
              name: contentList[a]
            }
            strList.push(temp)
          }
        } else {
          strList[0] = {
            key: 1,
            name: content
          }
        }
        return strList
      },
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        importance: undefined,
        name: undefined,
        typeId: undefined,
        systemType: undefined,
        level: undefined,
        sort: '+id'
      },
      sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
      featureOptions: [{ key: 0, label: '通用型' }, { key: 1, label: '内存型' }, { key: 2, label: 'IO密集型' }, { key: 3, label: 'CPU密集型' }],
      levelOptions: ['A', 'B', 'C', 'D'],
      typeOptions: [], // 应用分类
      sysTypeOp: [], // 应用类型
      portOptions: [], // 数据库端口
      redisOptions: [], // REDIS实例
      devOptions: [], // 开发人员
      hostOptions: [], // 主机
      portsArray: [], // 端口 - 新增时使用
      hostArray: [], // 主机 - 新增时使用
      redisArray: [], // redis实例 - 新增时使用
      developArray: [], // 开发者 - 新增时使用
      kubernetesEnvOptions: [], // k8s环境
      k8sEnvArray: [], // k8s环境数组
      showReviewer: false,
      temp: {
        id: undefined,
        name: '',
        gitUrl: '',
        comment: '',
        level: '',
        ownerId: '',
        qualityId: '',
        hostIds: '',
        k8sEnvs: '',
        ports: '',
        redis: '',
        developIds: '',
        typeId: '',
        systemType: '',
        features: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '修改',
        create: '新增'
      },
      dialogPvVisible: false,
      pvData: [],
      rules: {
        typeId: [{ required: true, message: '应用分类是必填项', trigger: 'blur' }],
        features: [{ required: true, message: '应用特性是必选项', trigger: 'blur' }],
        systemType: [{ required: true, message: '系统类型是必填项', trigger: 'blur' }],
        gitUrl: [{ required: true, message: 'gitUrl是必填项', trigger: 'blur' }],
        ownerId: [{ required: true, message: '负责人是必填项', trigger: 'blur' }],
        level: [{ required: true, message: '应用等级是必填项', trigger: 'blur' }],
        name: [{ required: true, message: '系统名称是必填项', trigger: 'blur' }],
        comment: [{ required: true, message: '应用描述是必填项', trigger: 'blur' }]
      },
      downloadLoading: false
    }
  },
  created() {
    this.getList()
    this.getTypeList()
    this.getSystemType()
    this.getPortList()
    this.getRedisList()
    this.getDevList()
    this.getHostList()
    this.getK8sEnvList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        const recordsList = response.data.records
        if (recordsList.length > 0) {
          for (let a = 0; a < recordsList.length; a++) {
            recordsList[a].hostNames = this.formatHost(recordsList[a].hostNames)
          }
        }
        this.list = recordsList
        this.total = response.data.total
        this.listLoading = false
      })
    },
    // k8s环境
    getK8sEnvList() {
      fetchEnv().then(response => {
        this.kubernetesEnvOptions = response.data
      })
    },
    getTypeList() {
      fetchTypeList().then(response => {
        this.typeOptions = response.data
      })
    },
    getSystemType() {
      fetchSystemType().then(response => {
        this.sysTypeOp = response.data
      })
    },
    getPortList() {
      fetchPortList().then(response => {
        this.portOptions = response.data
      })
    },
    getRedisList() {
      fetchRedisList().then(response => {
        this.redisOptions = response.data
      })
    },
    getDevList() {
      fetchDevList().then(response => {
        this.devOptions = response.data
      })
    },
    getHostList() {
      fetchHostList().then(response => {
        this.hostOptions = response.data
      })
    },
    // 搜索
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    // 修改条数
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    // 修改当前页码
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    // 删除操作
    handleDelete(row) {
      this.$confirm('此删除操作不可还原, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del({"id":row.id}).then(response => {
          this.getList()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      }).catch(() => {
      })
    },
    // 重新初始化数据
    resetTemp() {
      this.temp = {
        id: undefined,
        name: '',
        comment: '',
        gitUrl: '',
        level: '',
        ownerId: '',
        qualityId: '',
        k8sEnvs: '',
        hostIds: '',
        ports: '',
        redis: '',
        developIds: '',
        typeId: '',
        systemType: '',
        features: ''
      }
    },
    // 新增应用数据
    handleCreate() {
      this.resetTemp()
      this.redisArray = [] // redis实例 - 新增时使用
      this.portsArray = [] // 端口 - 新增时使用
      this.developArray = [] // 开发者 - 新增时使用
      this.hostArray = [] // 开发者 - 新增时使用
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    // 新增应用数据
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          if (this.portsArray.length === 0) {
            this.temp.ports = ''
          }
          if (this.portsArray.length === 1) {
            this.temp.ports = this.portsArray[0]
          }
          if (this.portsArray.length > 1) {
            this.temp.ports = this.portsArray.join(',')
          }
          if (this.redisArray.length === 0) {
            this.temp.redis = ''
          }
          if (this.redisArray.length === 1) {
            this.temp.redis = this.redisArray[0]
          }
          if (this.redisArray.length > 1) {
            this.temp.redis = this.redisArray.join(',')
          }
          if (this.developArray.length === 0) {
            this.temp.developIds = ''
          }
          if (this.developArray.length === 1) {
            this.temp.developIds = this.developArray[0]
          }
          if (this.developArray.length > 1) {
            this.temp.developIds = this.developArray.join(',')
          }
          if (this.hostArray.length === 0) {
            this.temp.hostIds = ''
          } else if (this.hostArray.length === 1) {
            this.temp.hostIds = this.hostArray[0]
          } else if (this.hostArray.length > 1) {
            this.temp.hostIds = this.hostArray.join(',')
          }
          if (this.temp.hostNames) {
            delete (this.temp.hostNames)
          }
          create(this.temp).then(() => {
            this.getList()
            this.dialogFormVisible = false
            this.$notify({
              title: '成功',
              message: '创建成功',
              type: 'success',
              duration: 2000
            })
          })
        }
      })
    },
    // 修改数据
    handleUpdate(row) {
      this.temp = Object.assign({}, row) // copy obj

      this.portsArray = []
      if (this.temp.ports.indexOf(',') !== -1) {
        this.portsArray = this.temp.ports.split(',')
      } else {
        if (this.temp.ports !== '') {
          this.portsArray[0] = this.temp.ports
        }
      }

      this.redisArray = []
      if (this.temp.redis.indexOf(',') !== -1) {
        this.redisArray = this.temp.redis.split(',')
      } else {
        if (this.temp.redis !== '') {
          this.redisArray[0] = this.temp.redis
        }
      }
      this.developArray = []
      if (this.temp.developIds.indexOf(',') !== -1) {
        var developStrArray = this.temp.developIds.split(',')
        for (var i = 0; i < developStrArray.length; i++) {
          this.developArray.push(parseInt(developStrArray[i]))
        }
      } else {
        if (this.temp.developIds !== '') {
          this.developArray[0] = parseInt(this.temp.developIds)
        }
      }

      this.hostArray = []
      if (this.temp.hostIds.indexOf(',') !== -1) {
        var hostStrArray = this.temp.hostIds.split(',')
        for (var j = 0; j < hostStrArray.length; j++) {
          this.hostArray.push(parseInt(hostStrArray[j]))
        }
      } else {
        if (this.temp.hostIds !== '') {
          this.hostArray[0] = parseInt(this.temp.hostIds)
        }
      }
      this.k8sEnvArray = []
      if (this.temp.k8sEnvs.indexOf(',') !== -1) {
        var k8sStrArray = this.temp.k8sEnvs.split(',')
        for (let p = 0; p < k8sStrArray.length; p++) {
          this.k8sEnvArray.push(k8sStrArray[p])
        }
      } else {
        if (this.temp.k8sEnvs !== '') {
          this.k8sEnvArray[0] = this.temp.k8sEnvs
        }
      }

      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    // 更新数据
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          if (this.portsArray.length === 0) {
            this.temp.ports = ''
          }
          if (this.portsArray.length === 1) {
            this.temp.ports = this.portsArray[0]
          }
          if (this.portsArray.length > 1) {
            this.temp.ports = this.portsArray.join(',')
          }
          if (this.redisArray.length === 0) {
            this.temp.redis = ''
          }
          if (this.redisArray.length === 1) {
            this.temp.redis = this.redisArray[0]
          }
          if (this.redisArray.length > 1) {
            this.temp.redis = this.redisArray.join(',')
          }
          if (this.developArray.length === 0) {
            this.temp.developIds = ''
          }
          if (this.developArray.length === 1) {
            this.temp.developIds = this.developArray[0]
          }
          if (this.developArray.length > 1) {
            this.temp.developIds = this.developArray.join(',')
          }

          if (this.hostArray.length === 0) {
            this.temp.hostIds = ''
          }
          if (this.hostArray.length === 1) {
            this.temp.hostIds = this.hostArray[0]
          }
          if (this.hostArray.length > 1) {
            this.temp.hostIds = this.hostArray.join(',')
          }

          if (this.k8sEnvArray.length === 0) {
            this.temp.k8sEnvs = ''
          }
          if (this.k8sEnvArray.length === 1) {
            this.temp.k8sEnvs = this.k8sEnvArray[0]
          }
          if (this.k8sEnvArray.length > 1) {
            this.temp.k8sEnvs = this.k8sEnvArray.join(',')
          }

          if (this.temp.hostNames) {
            delete (this.temp.hostNames)
          }
          const tempData = Object.assign({}, this.temp)
          update(tempData).then(() => {
            this.getList()
            this.dialogFormVisible = false
            this.$notify({
              title: '成功',
              message: '更新成功',
              type: 'success',
              duration: 2000
            })
          })
        }
      })
    },
    // 复制并添加
    handleCopyAndAdd(row) {
      this.temp = Object.assign({}, row)
      this.temp.name = this.temp.name + '_' + parseTime(+new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
      this.portsArray = []
      if (this.temp.ports.indexOf(',') !== -1) {
        this.portsArray = this.temp.ports.split(',')
      } else {
        if (this.temp.ports !== '') {
          this.portsArray[0] = this.temp.ports
        }
      }

      this.redisArray = []
      if (this.temp.redis.indexOf(',') !== -1) {
        this.redisArray = this.temp.redis.split(',')
      } else {
        if (this.temp.redis !== '') {
          this.redisArray[0] = this.temp.redis
        }
      }
      this.developArray = []
      if (this.temp.developIds.indexOf(',') !== -1) {
        var developStrArray = this.temp.developIds.split(',')
        for (var i = 0; i < developStrArray.length; i++) {
          this.developArray.push(parseInt(developStrArray[i]))
        }
      } else {
        if (this.temp.developIds !== '') {
          this.developArray[0] = parseInt(this.temp.developIds)
        }
      }

      this.hostArray = []
      if (this.temp.hostIds.indexOf(',') !== -1) {
        var hostStrArray = this.temp.hostIds.split(',')
        for (var j = 0; j < hostStrArray.length; j++) {
          this.hostArray.push(parseInt(hostStrArray[j]))
        }
      } else {
        if (this.temp.hostIds !== '') {
          this.hostArray[0] = parseInt(this.temp.hostIds)
        }
      }
      this.k8sEnvArray = []
      if (this.temp.k8sEnvs.indexOf(',') !== -1) {
        var k8sStrArray = this.temp.k8sEnvs.split(',')
        for (let p = 0; p < k8sStrArray.length; p++) {
          this.k8sEnvArray.push(k8sStrArray[p])
        }
      } else {
        if (this.temp.k8sEnvs !== '') {
          this.k8sEnvArray[0] = this.temp.k8sEnvs
        }
      }

      this.dialogStatus = 'create'
      this.dialogFormVisible = true
    }
  }
}
</script>
